import Vue from 'vue'
import Vuex from 'vuex'
import user from './modules/user'
import publicData from './modules/publicData'
import getters from './getters'
Vue.use(Vuex)

export default new Vuex.Store({
  modules: {
    user,
    publicData
  },
  //存储数据
  state: {
    locale: 'en',
    campaigns: null,
  },
  //编写操作state里变量方法
  mutations: {
    changeLocale(state, newState) {
      localStorage.setItem('locale', newState);
      state.locale = newState
    },
    changeCampaigns(state, newCampaigns) {
      localStorage.setItem('campaigns', JSON.stringify(newCampaigns));
      state.campaigns = newCampaigns
    },
  },
  getters
})
